from fastapi import APIRouter
from loguru import logger
from code.app.services.api_call import APICall
from code.app.services.image_generation_object import OutPainting
from code.app.services.response import Response
from code.app.utils.object_utils import convert_to_dict

# 图像画面扩展接口路由
out_painting_app = APIRouter()


@out_painting_app.post('/out-painting/create/task')
def create_task(request_param: OutPainting.OutPaintingRequest) -> Response:
    _input = convert_to_dict(request_param.input)
    _parameters = convert_to_dict(request_param.parameters)
    api_response = APICall.async_call(model=request_param.model,
                                      input=_input,
                                      parameters=_parameters)
    logger.info(f'out-painting create_task api_response：{api_response.__str__()}')
    return Response.from_response(api_response)

